package com.recruit.controller;

import com.recruit.model.CompanyDO;
import com.recruit.model.HrCompanyDO;
import com.recruit.service.HrCompanyService;
import com.recruit.vo.CreatedVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.Positive;

/**
 * @author DHF
 */
@RestController
@RequestMapping("/recruit/hr-company")
@Api(tags = "公司-hr处理接口")
public class HrCompanyController {

    @Resource
    private HrCompanyService hrCompanyService;

    @PostMapping("")
    @ApiOperation(value = "创建hr和公司关联")
    public CreatedVO create(
            @ApiParam(value = "hrId", required = true)
            @RequestParam @Positive(message = "{id.positive}") Integer hrId,
            @ApiParam(value = "公司id", required = true)
            @RequestParam @Positive(message = "{id.positive}") Integer companyId) {
        hrCompanyService.create(hrId, companyId);
        return new CreatedVO(1);
    }

    /**
     * 根据hr_id查询hr对应的公司信息
     *
     * @param hrId
     * @return
     */
    @GetMapping("/{hrId}")
    @ApiOperation(value = "根据hr_id查询hr对应的公司信息")
    public CompanyDO get(
            @ApiParam(value = "hrId", required = true)
            @PathVariable(value = "hrId") @Positive(message = "{id.positive}") Integer hrId) {
        return hrCompanyService.getCompany(hrId);
    }

    /**
     * 根据hr_id查询记录
     *
     * @param hrId
     * @return
     */
    @GetMapping("/search/{hrId}")
    @ApiOperation(value = "根据hr_id查询记录")
    public HrCompanyDO getByHrId(
            @ApiParam(value = "hrId", required = true)
            @PathVariable(value = "hrId") @Positive(message = "{id.positive}") Integer hrId) {
        return hrCompanyService.getByHrId(hrId);
    }

    /**
     * 根据companyId查看公司信息
     *
     * @param companyId
     * @return
     */
    @GetMapping("/company/{companyId}")
    @ApiOperation(value = "根据companyId查看公司信息")
    public CompanyDO getCompany(
            @ApiParam(value = "公司id", required = true)
            @PathVariable(value = "companyId") @Positive(message = "{id.positive}") Integer companyId) {
        return hrCompanyService.getCompanyInfo(companyId);
    }
}
